home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OCFINC.PAK / EXCEPT.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  130 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectComponents
  3. // Copyright (c) 1994, 1997 by Borland International, All Rights Reserved
  4. //
  5. // $Revision:   2.4  $
  6. //
  7. // OCF Exception classes
  8. //     NOTE: All OCF Exception classes are defined here except for TXAuto,
  9. //           the exception used in automation failures. [See AUTODEFS.H
  10. //           for TXAuto].
  11. //----------------------------------------------------------------------------
  12. #if !defined(OCF_EXCEPT_H)
  13. #define OCF_EXCEPT_H
  14.  
  15. #if !defined(OCF_DEFS_H)
  16. # include <ocf/defs.h>
  17. #endif
  18. #if !defined(SERVICES_CSTRING_H)
  19. # include <services/cstring.h>
  20. #endif
  21. #if !defined(SERVICES_EXCEPT_H)
  22. # include <services/except.h>
  23. #endif
  24. #if !defined(SERVICES_OLE2INC_H)
  25. # include <services/ole2inc.h>
  26. #endif
  27.  
  28. #if defined(BI_NAMESPACE)
  29. namespace OCF {
  30. #endif
  31.  
  32. //
  33. // class TXOle
  34. // ~~~~~ ~~~~~
  35. // OLE API related exception object
  36. //
  37. class TXOle : public TXBase {
  38.   public:
  39.     TXOle(const string& msg, HRESULT stat);
  40.     TXOle(const TXOle& src);
  41.    ~TXOle();
  42.  
  43.     TXOle*      Clone();
  44.     void        Throw();
  45.  
  46.     static void Check(HRESULT stat, const char far* msg);
  47.     static void Check(HRESULT stat);
  48.     static void Throw(HRESULT stat, const char far* msg);
  49.     static void OleErrorFromCode(HRESULT stat, char far* buffer, int size);
  50.  
  51.     const long  Stat;
  52. };
  53.  
  54. //
  55. //
  56. //
  57. inline
  58. TXOle::TXOle(const string& msg, HRESULT stat)
  59.       : TXBase(msg), Stat((long)stat)
  60. {}
  61.  
  62. //
  63. //
  64. //
  65. inline TXOle::TXOle(const TXOle& src)
  66.              : TXBase(src), Stat(src.Stat)
  67. {}
  68.  
  69. //
  70. // Macro to simply error checking of OLE calls
  71. //
  72. #if (__DEBUG > 0) || defined(__WARN)
  73. # define OLECALL(func, msg) TXOle::Check(func, msg)
  74. #else
  75. # define OLECALL(func, msg) TXOle::Check(func)
  76. #endif
  77.  
  78.  
  79. //
  80. // class TXObjComp
  81. // ~~~~~ ~~~~~~~~~
  82. // Base OC exception class
  83. //
  84. class TXObjComp : public TXOle {
  85.   public:
  86.     enum TError {
  87.  
  88.       // Application Errors
  89.       //
  90.       xNoError,
  91.       xBOleLoadFail,
  92.       xBOleVersFail,
  93.       xBOleBindFail,
  94.       xDocFactoryFail,
  95.  
  96.       // Doc & Part Errors
  97.       //
  98.       xMissingRootIStorage,
  99.       xInternalPartError,
  100.       xPartInitError,
  101.  
  102.       // Storage Errors
  103.       //
  104.       xRootStorageOpenError,
  105.       xStorageOpenError,
  106.       xStorageILockError,
  107.       xStreamOpenError,
  108.     };
  109.  
  110.     TXObjComp(TError err, const string& msg, HRESULT stat = HR_FAIL)
  111.       : TXOle(msg, stat), ErrorCode(err) {}
  112.     TXObjComp(const TXObjComp& src)
  113.       : TXOle(src), ErrorCode(src.ErrorCode) {}
  114.    ~TXObjComp();
  115.  
  116.     TXObjComp*  Clone();
  117.     void        Throw();
  118.  
  119.     static void Check(HRESULT stat, TError err, const char far* msg = 0);
  120.     static void Throw(TError err, HRESULT stat = HR_FAIL, const char far* msg = 0);
  121.  
  122.     const TError ErrorCode;
  123. };
  124.  
  125. #if defined(BI_NAMESPACE)
  126. } // namespace OCF
  127. #endif
  128.  
  129. #endif  //  OCF_EXCEPT_H
  130.